package com.example.hellogridview;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

public class HelloGridviewActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		GridView gridView = (GridView) findViewById(R.id.gridview);
		String[] thumbIds = {MediaStore.Images.Thumbnails._ID}; 
		Log.i("StartingCursor", "Cursor is starting now...");
		Cursor thumbNailCursor = getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, thumbIds, 
				null, null, null); // nulls are Datatype, dataTypeArgs, sortOrder
		Log.i("MainActivity", "Setting Image Adapter...");
		gridView.setAdapter(new ImageAdapterHelloGridView(this, thumbNailCursor));
		Log.i("MainActivity", "Image Adapter set");
		
		gridView.setOnItemClickListener(new OnItemClickListener(){
			public void onItemClick(AdapterView<?> parent, View v, int position, long id){
				Toast.makeText(HelloGridviewActivity.this,"position = " + position + ", ID = " + id, Toast.LENGTH_SHORT).show();
				
			}
		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
